package com.maiji.cloud.controller.shopingmall;

import com.maiji.cloud.controller.BaseController;
import com.maiji.cloud.request.shopingmall.AddExchangeLogReqDto;
import com.maiji.cloud.request.shopingmall.GetExchangeLogReqDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.response.shopingmall.GetDiscountCouponListResDto;
import com.maiji.cloud.response.shopingmall.GetExchangeLogResDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 优惠券
 * Description:  
 * @author zhanglr  
 * @date 2019年6月24日
 */
@RestController
@Api(tags = {"优惠券"})
@RequestMapping("/couponsInterface/")
public class CouponsController extends BaseController {
	/**
	 * 获去可兑换优惠券列表
	 * @return
	 */
	@PostMapping("getDiscountCouponList")
	@ApiOperation(value = "获去可兑换优惠券列表")
	public GetDiscountCouponListResDto getDiscountCouponList(@RequestHeader String maijiToken){
		HttpHeaders headers = new HttpHeaders();
		headers.add("maijiToken", maijiToken);
		HttpEntity<String> httpEntity = new HttpEntity<>(headers);
		return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/coupons/getDiscountCouponList", httpEntity, GetDiscountCouponListResDto.class);
	}
	
	/**
	 * 获取积分兑换记录列表
	 * @param getExchangeLogReqDto
	 * @return
	 */
	@PostMapping("getExchangeLogList")
	@ApiOperation(value = "获取积分兑换记录列表")
	public GetExchangeLogResDto getExchangeLogList(GetExchangeLogReqDto getExchangeLogReqDto,@RequestHeader String maijiToken){
		getExchangeLogReqDto.setMaijiToken(maijiToken);
		return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/coupons/getExchangeLogList", getExchangeLogReqDto, GetExchangeLogResDto.class);
	}                                                              
	/**
	 * 用户兑换商品或优惠券
	 * @param param
	 * @return
	 */
	@PostMapping("addExchangeLog")
	@ApiOperation(value = "用户兑换商品或优惠券")
	public BaseResDto addExchangeLog(AddExchangeLogReqDto param,@RequestHeader String maijiToken){
		param.setMaijiToken(maijiToken);
		return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/coupons/addExchangeLog", param, BaseResDto.class);
	}
	/**
	 * 可用优惠券列表
	 * @return
	 */
	@PostMapping("getUsableDiscountCouponList")
	@ApiOperation(value = "可用优惠券列表")
	public GetDiscountCouponListResDto getUsableDiscountCouponList(@RequestHeader String maijiToken){
		
		HttpHeaders headers = new HttpHeaders();
		headers.add("maijiToken", maijiToken);
		HttpEntity<String> httpEntity = new HttpEntity<>(headers);
		return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/coupons/getUsableDiscountCouponList", httpEntity, GetDiscountCouponListResDto.class);
	}
	
}
